package com.weather.web.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weather.common.annotation.Log;
import com.weather.common.core.controller.BaseController;
import com.weather.common.core.domain.AjaxResult;
import com.weather.common.enums.BusinessType;
import com.weather.business.domain.NmCity;
import com.weather.business.service.INmCityService;
import com.weather.common.utils.poi.ExcelUtil;
import com.weather.common.core.page.TableDataInfo;

/**
 * 城市Controller
 *
 * @author ruoyi
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/business/city")
public class NmCityController extends BaseController
{
    @Autowired
    private INmCityService nmCityService;

    /**
     * 查询城市列表
     */
    @PreAuthorize("@ss.hasPermi('business:city:list')")
    @GetMapping("/list")
    public TableDataInfo list(NmCity nmCity)
    {
        startPage();
        List<NmCity> list = nmCityService.selectNmCityList(nmCity);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('business:city:list')")
    @GetMapping("/listAll")
    public List<NmCity> All(NmCity nmCity)
    {
        List<NmCity> list = nmCityService.selectNmCityList(nmCity);
        return list;
    }

    /**
     * 导出城市列表
     */
    @PreAuthorize("@ss.hasPermi('business:city:export')")
    @Log(title = "城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NmCity nmCity)
    {
        List<NmCity> list = nmCityService.selectNmCityList(nmCity);
        ExcelUtil<NmCity> util = new ExcelUtil<NmCity>(NmCity.class);
        util.exportExcel(response, list, "城市数据");
    }

    /**
     * 获取城市详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:city:query')")
    @GetMapping(value = "/{cityid}")
    public AjaxResult getInfo(@PathVariable("cityid") String cityid)
    {
        return success(nmCityService.selectNmCityByCityid(cityid));
    }

    /**
     * 新增城市
     */
    @PreAuthorize("@ss.hasPermi('business:city:add')")
    @Log(title = "城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NmCity nmCity)
    {
        return toAjax(nmCityService.insertNmCity(nmCity));
    }

    /**
     * 修改城市
     */
    @PreAuthorize("@ss.hasPermi('business:city:edit')")
    @Log(title = "城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NmCity nmCity)
    {
        return toAjax(nmCityService.updateNmCity(nmCity));
    }

    /**
     * 删除城市
     */
    @PreAuthorize("@ss.hasPermi('business:city:remove')")
    @Log(title = "城市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cityids}")
    public AjaxResult remove(@PathVariable String[] cityids)
    {
        return toAjax(nmCityService.deleteNmCityByCityids(cityids));
    }
}
